package legoserver;


import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import javax.swing.*;

/**
 * basic start routines for the A* search
 */
public class AStar {
  ButtonGroup group;
 // JRadioButton start;
  //JComboBox method = new JComboBox();
  //JButton go, clear,exit;
  //Container contentPane = getContentPane();
  AStarMap map;
  AStarPathFinder finder;

  /**
   * contructor creates GUI
   */
  public AStar() {
    map = new AStarMap();
    finder = new AStarClassic();
    finder.findPath(map);
      
    /*contentPane.setLayout(new BorderLayout());
    JPanel tools = new JPanel(new GridLayout(1, 3, 5, 5));
    JPanel buttons = new JPanel(new GridLayout(1, 3, 5, 5));
    group = new ButtonGroup();
    go = new JButton("Go");
    clear = new JButton("Clear");
    exit =  new JButton("Exit");
 
    go.addActionListener(this);
    clear.addActionListener(this);
    exit.addActionListener(this);

    buttons.add(go);
    buttons.add(clear);
    buttons.add(exit);
    tools.add(buttons);
    contentPane.add(map, "Center");
    contentPane.add(tools, "North");*/
  }

  /**
   * destroy object
   * @param object
   */
  public static void destroy() {
  }
  
  public boolean isBusy() {
      return finder.isBusy();
  }
 
  /**
   * statechange listener for setting blocks on the grid
   * @param e item event
   */
  /*public void itemStateChanged(ItemEvent e) {
    if (e.getSource() == method) {
      switch (method.getSelectedIndex()) {
        case 0:
          finder = new AStarClassic();
          break;
      }
      return;
    }
  }*/

  /**
   * action listener for the buttons
   * @param e action event
   */
  /*public void actionPerformed(ActionEvent e) {
    if (e.getSource() == go) { finder.findPath(map); }
    if (e.getSource() == clear) {
      AStarGridCell.clearAll();
      repaint();
    }
    if (e.getSource() == exit) {System.exit(0);}
  }*/
  /**
   * sets blocks with different weights
   * @param maze integer double array with cost values
   * @param weidth of the maze
   * @param height of the maze
   */
  public void setMaze(int[][] maze, int weidth, int height) {
    for (int i = 0; i < height; i++) {
      for (int j = 0; j < weidth; j++) {
        if (maze[j][i] == 100) { map.setBlock(j, i, AStarGridCell.BLOCK); }
        else if (maze[j][i] == 10) { map.setBlock(j, i, AStarGridCell.VERY_TOUGH); }
        else if (maze[j][i] == 5) { map.setBlock(j, i, AStarGridCell.TOUGH); }
      }
    }
  }

  /**
   * gets the solution of the A* search
   * @return vector with coordinates of the solution
   */
  public Vector getSolution() {
    return finder.getSolution();
  }
}